package com.kaviddiss.bootquartz.controller;

import com.kaviddiss.bootquartz.service.JobService;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by Studio on 2017/5/20.
 */
@RestController
@RequestMapping(value = "/job")
public class JobController {

    @Autowired
    JobService jobService;

    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public String createJob(@RequestParam String className,@RequestParam String jobName, @RequestParam String triggerName, @RequestParam String cron
            , @RequestParam String content) throws SchedulerException, ClassNotFoundException {
        boolean a = jobService.createJob(className,jobName,triggerName,cron,content);
        if(a){
            return "success";
        }else {
            return "false";
        }
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public String deleteJob(@RequestParam String jobName) throws SchedulerException, ClassNotFoundException {
        boolean a = jobService.deleteJob(jobName);
        if(a){
            return "success";
        }else {
            return "false";
        }
    }


}
